<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS对象_RegExp对象</title>

  <script>

      // RegExp 正则对象
      // 创建
      var exp = new RegExp("^\\w{6,12}$");
      var exp2 = /^\w{6,12}$/;

      //alert(exp);
      //alert(exp2);

      var username = "zhangsan";

      // 验证
      var flag = exp.test(username);
      alert(flag);

  </script>

</head>
<body>

</body>
</html>